let express = require('express')
let fs = require('fs').promises
let parser = require('body-parser') // 解析前端请求体传递的参数
let app = express()
let http = require('https')

app.listen(8080, () => {
  console.log("服务其在8080");
})
app.use((req, res, next) => {
  res.header('qq', '66') // 设置响应头
  next()
})

// parse application/x-www-form-urlencoded
app.use(parser.urlencoded({ extended: false }))
// parse application/json
app.use(parser.json())

app.use(express.static('./page'))

app.post('/list', function (req, res) {
  console.log(req.body)
  // 后端设置浏览器的cookie的时候 对应的值跟前端设置cookie对应的值是一样的
  res.header("set-cookie", 'www=23424;expires=Thu, 18 Dec 2043 12:00:00 GMT') // 给前端设置cookie
  res.send(JSON.stringify([1, 2, 3]))
})


app.get('/ajax/movieOnInfoList', function (req, res) {
  // res.send(JSON.stringify([1, 2, 3]))
  const options = {
    hostname: 'wq.360buyimg.com',
    port: 443,
    path: '/js/common/dest/m.xstorage.client.min.js',
    method: 'get',
  };
  let req2 = http.request('https://m.maoyan.com/ajax/movieOnInfoList?token=&optimus_uuid=AA1A4E605EBE11EB81B27DDD4D787814E325A6C0C40A4CF9B19BE0477E7B791B&optimus_risk_level=71&optimus_code=10', (res2) => {
    let str = '';
    console.log(6666)
    res2.on('data', chunk => {
      str += chunk
    })
    res2.on('end', () => {
      // console.log(str)
      res.send(str)
    })
  })
  req2.end()

})
